Passed
Push — master ( f91fcb...083070 )
by Night
01:21
created

stringFuncs.insertAfterNth   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
nc 2
nop 5
dl 0
loc 8
rs 10
c 1
b 0
f 0
1
/** global: UB */
2
3
var stringFuncs = {
4
	
5
	insertAfterNth(find, insert, nth = 1, caseSensitive = true, wholeWords = false) {
6
		var text = this.toString();
7
		var index = text.indexOfNth(find, nth, wholeWords, caseSensitive);
8
		if (index > -1) {
9
			return text.insertAt(insert, index + find.Length);
10
		}
11
		return text;
12
	},
13
	insertAfterLast(find, insert, caseSensitive = true, wholeWords = false) {
14
		var text = this.toString();
15
		return text.insertAfterNth(find, insert, 1, true, caseSensitive, wholeWords);
16
	},
17
	insertAfterFirst(find, insert, caseSensitive = true, wholeWords = false) {
18
		var text = this.toString();
19
		return text.insertAfterNth(find, insert, 1, false, caseSensitive, wholeWords);
20
	},
21
22
	insertBeforeNth(find, insert, nth = 1, caseSensitive = true, wholeWords = false) {
23
		var text = this.toString();
24
		var index = text.indexOfNth(find, nth, wholeWords, caseSensitive);
25
		if (index > -1) {
26
			return text.insertAt(insert, index);
27
		}
28
		return text;
29
	},
30
	insertBeforeLast(find, insert, caseSensitive = true, wholeWords = false) {
31
		var text = this.toString();
32
		return text.insertBeforeNth(find, insert, 1, true, caseSensitive, wholeWords);
33
	},
34
	insertBeforeFirst(find, insert, caseSensitive = true, wholeWords = false) {
35
		var text = this.toString();
36
		return text.insertBeforeNth(find, insert, 1, false, caseSensitive, wholeWords);
37
	},
38
	
39
	none:null
40
};
41
42
// register funcs
43
UB.registerFuncs(String.prototype, stringFuncs);